<div class="layui-fluid layui-anim website-anim" id="website-standard" lay-title="评审标准管理">
    <div class="layui-row website-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body website-table-full">
                    <form class="layui-form layui-table-form" lay-filter="standard-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md8">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">关键词</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="name" autocomplete="off" class="layui-input" placeholder="请输入名称">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md4 layui-col-sm12 layui-col-xs12 table-action-area ">
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-blue-plain table-action" id="query">
                                    查询
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-green-plain table-action" id="reset">
                                    重置
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-green-plain" id="addAll">
                                    新增
                                </div>
                            </div>
                        </div>
                    </form>
                    <table lay-filter="standardTable" lay-data="{id: 'standardTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="standard-option">
    <span shiro:lacksPermission="standard:list,standard:update,standard:delete">
        <span class="layui-badge-dot website-bg-orange"></span> 无权限
    </span>
    <a lay-event="detail" shiro:hasPermission="standard:list" class="website-green">查看</a>
    <a lay-event="edit" shiro:hasPermission="standard:update" class="website-blue">编辑</a>
    <a lay-event="del" shiro:hasPermission="standard:delete" class="website-red">删除</a>
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['jquery', 'form', 'table', 'website'], function () {
        var $ = layui.jquery,
            website = layui.website,
            form = layui.form,
            table = layui.table,
            $view = $('#website-standard'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $addAll = $view.find('#addAll'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createTime', type: null},
            tableIns,
            createTimeFrom,
            createTimeTo;
        form.render();
        initTable();

        table.on('tool(standardTable)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'detail') {
                website.navigate("/biz/standard/detail/"+ data.standardId);
               /* website.modal.view('评审标准信息', 'biz/standard/detail/' + data.standardId, {
                    area: $(window).width() <= 750 ? '95%' : '660px'
                });*/
            }
            if (layEvent === 'del') {
                website.modal.confirm('删除信息', '确定删除该信息？', function () {
                    deleteStandards(data.standardId);
                });
            }
            if (layEvent === 'edit') {
                website.navigate("/biz/standard/standardUpdate/"+ data.standardId);
            }
        });
        table.on('sort(standardTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });
        $query.on('click', function () {
            var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });

        $reset.on('click', function () {
            $searchForm[0].reset();
            sortObject.type = 'null';
            createTimeTo = null;
            createTimeFrom = null;
            tableIns.reload({where: getQueryParams(), page: {curr: 1}, initSort: sortObject});
        });
        $addAll.on('click', function () {
          /*  website.navigate("/biz/standard/standardAdd");*/
            var cacheDataDel = table.cache["standardTable"];
            if(cacheDataDel.length==0){
                website.navigate("/biz/standard/standardAdd");
            }else {
                website.alert.error('只允许一条数据');
                return false;
            }
        });

        function initTable() {
            tableIns = website.table.init({
                elem: $view.find('table'),
                id: 'standardTable',
                url: ctx + 'standard/list',
                cols: [[
                    /*{type: 'checkbox'},*/
                    { type: 'numbers', title: '序号', },
                    {field: 'name', title: '评审标准名称', minWidth: 100},
                    {field: 'explainContent', title: '填表要求说明', minWidth: 100},
                    {title: '操作', align:'center', toolbar: '#standard-option', minWidth: 200}
                ]]
            });
        }
        function getQueryParams() {
            var params = $searchForm.serializeJson();
            var createTime = params.time;
            if (createTime) {
                createTimeFrom = createTime.split(' - ')[0];
                createTimeTo = createTime.split(' - ')[1];
            }
            params.invalidate_ie_cache = new Date();
            params.createTimeFrom = createTimeFrom;
            params.createTimeTo = createTimeTo;
            return params;
        }
        function deleteStandards(standardIds) {
            website.post(ctx + 'standard/delete/' + standardIds, null, function () {
                website.alert.success('删除成功');
                $query.click();
            });
        }


    })
</script>